home *** CD-ROM | disk | FTP | other *** search
/ Transactor / Transactor_16_1987_Transactor_Publishing.d64 / convert c-power < prev    next >
Text File  |  2023-02-26  |  4KB  |  170 lines

  1. /* program to convert Super C      */
  2. /* files to/from SEQ files         */
  3. /* converting filetypes            */
  4. /* and control codes               */
  5.  
  6. #define POWER  
  7. #ifdef POWER
  8. #include "stdio.h"
  9. #define CLR '\223'
  10. #else
  11. #include "h:stdio.h"
  12. #endif
  13.  
  14. char inname[25];
  15. char outname[25];
  16. #ifdef POWER
  17.     FILE inchan;
  18.     FILE outchan;
  19. #else
  20. file inchan;
  21. file outchan;
  22. #endif
  23.  
  24. main()
  25. {SHIFT-+}
  26.     int menu();
  27.  
  28.     int choice ;
  29.     int status = 0;
  30.     char inbuff[255];
  31.     char outbuff[255];
  32.  
  33.     while ( ( choice = menu() ) != '0' )
  34.     {SHIFT-+}
  35.          choice = ( choice == '1' ) ? 1 : 2 ;
  36.          putchar(CLR);
  37. #ifdef POWER
  38.              getchar();
  39. #endif
  40.          namefile("Source ", inname);
  41.          namefile("Destination ", outname);
  42.          modnames( choice );
  43. #ifdef POWER
  44.             inchan = fopen(inname,"r");
  45.             outchan = fopen(outname,"w");
  46. #else
  47.             inchan = open(8,2,inname);
  48.             outchan = open(8,3,outname);
  49. #endif
  50. status = 0;
  51.  
  52.          while (!status)              /* read a line and convert it */
  53.          {SHIFT-+}
  54.              fgets(inbuff, 254, inchan);
  55. #ifdef POWER
  56.                 status = feof(inchan);
  57. #else
  58.                 status = EOF;
  59. #endif
  60.              convert(choice, inbuff, outbuff);
  61.              fputs(outbuff, outchan);
  62.              printf("\n%s", outbuff );
  63.          {SHIFT--}
  64.  
  65.          close(inchan);
  66.          close(outchan);
  67.     {SHIFT--}
  68. {SHIFT--}
  69.  
  70.  modnames( choice )                    /* modify filename for */
  71.  int choice;
  72.  {SHIFT-+}                                          /* read/write usr/seq  */
  73.     switch (choice)
  74.     {SHIFT-+}
  75.         case 1 :
  76.             strcat(inname, ",u,r");
  77.             strcat(outname, ",s,w");
  78.             break;
  79.         case 2 :
  80.             strcat(inname, ",s,r");
  81.             strcat(outname, ",u,w");
  82.             break;
  83.     {SHIFT--}
  84.  {SHIFT--}
  85.  
  86.  namefile(filetype, name)                  /* input filename */
  87.  char *filetype;
  88.  char *name;                          /* pass pointer to filename */
  89.  {SHIFT-+}
  90.     printf("\n%sfile name: ",filetype);
  91.     gets(name,16);
  92.  
  93.     if ( *( name + ( strlen(name) -1 ) ) == '\n' )   /* Super C gets() fix */
  94.       *( name + ( strlen(name) -1 ) ) = '\0' ;
  95.  {SHIFT--}
  96.  
  97. int menu()
  98. {SHIFT-+}
  99.     int choice;
  100.     do
  101.     {SHIFT-+}
  102.         printf("%c\n",CLR);
  103.         printf(" 1. Super C to Sequential\n");
  104.         printf(" 2. Sequential to Super C\n\n");
  105.         printf(" 0. EXIT");
  106.         choice = getchar();
  107.     {SHIFT--}
  108.     while ( ( choice != '0' ) && ( choice != '1' ) && ( choice != '2' ) );
  109.     return choice;
  110. {SHIFT--}
  111.  
  112. convert(choice, inbuff, outbuff)
  113. int choice;
  114. char inbuff[];
  115. char outbuff[];
  116. {SHIFT-+}
  117.  
  118.    static int linenum = 0 ;
  119.    int inndex=0;
  120.    int outndex=0;
  121.  
  122.    if ( linenum == 0 )
  123.        switch (choice)
  124.        {SHIFT-+}
  125.            case 1:
  126.                inndex +=3 ;
  127.                linenum = 1 ;
  128.                copybuff(inbuff, outbuff, inndex, outndex);
  129.                break;
  130.  
  131.            case 2:
  132.                outbuff[0] = 133;
  133.                outbuff[1] = 129;
  134.                outbuff[2] = 5;
  135.                outndex +=3;
  136.                linenum = 1;
  137.                copybuff( inbuff, outbuff, inndex, outndex );
  138.                break;
  139.        {SHIFT--}
  140.    else
  141.         switch (choice)
  142.         {SHIFT-+}
  143.            case 1:
  144.                 inndex++;
  145.                 copybuff(inbuff, outbuff, inndex, outndex);
  146.                 break;
  147.  
  148.            case 2:
  149.                    outbuff[0] = 5;
  150.                    outndex++;
  151.                    copybuff(inbuff, outbuff, inndex, outndex);
  152.                    break;
  153.         {SHIFT--}
  154. {SHIFT--}
  155.  
  156. copybuff( inbuff, outbuff, inndex, outndex )
  157. char inbuff[];
  158. char outbuff[];
  159. int  inndex;
  160. int  outndex;
  161. {SHIFT-+}
  162.    do
  163.    {SHIFT-+}
  164.        outbuff[  outndex ] = inbuff[  inndex ];
  165.        inndex++;
  166.        outndex++;
  167.    {SHIFT--}
  168.    while( inndex <= strlen( inbuff ) );
  169. {SHIFT--}
  170.